//
//  JJHomeViewModel.swift
//  JJSina
//
//  Created by mac on 2017/12/6.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class JJHomeViewModel: NSObject {

    lazy var dataArray: [JJStatusViewModel] = [JJStatusViewModel]()
}

extension JJHomeViewModel {
    // MARK: - 请求用户首页数据
    func getUserHomeData(isFinish: @escaping (Bool)->()) {
        JJNetworkTools.shared.loadUserData(success: { (response) in
            guard let resDict = response as? [String: Any] else {
                isFinish(false)
                return
            }
            guard let res = resDict["statuses"] else {
                isFinish(false)
                return
            }
            //            print(res)
            let statusArray = NSArray.yy_modelArray(with: JJHomeModel.self, json: res) as! [JJHomeModel]
            var tempArray: [JJStatusViewModel] = [JJStatusViewModel]()
            for homeModel in statusArray {
                let statusModel = JJStatusViewModel()
                statusModel.homeModel = homeModel
                tempArray.append(statusModel)
            }
            
            //            print(tempArray)
            self.dataArray = tempArray
            isFinish(true)
        }) { (error) in
            print("shibai", error)
            isFinish(false)
        }
    }
}
